/*
 * IBM Corporation.
 * Copyright (c) 2014 All Rights Reserved.
 */

package com.ibm.iisp.dataie.model;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import com.ibm.iisp.common.vo.AuditVO;

/**
 * 类作用：
 * 
 * @author Johnny@cn.ibm.com 使用说明：
 */
@Entity
@Table(name = "IISP_DATA_IE_IMPORT")
@NamedQueries({
	@NamedQuery(name = DataImport.QUERY_BY_TABLE, query = "select dt from DataImport dt where dt.tableName = :tableName"),
	@NamedQuery(name = DataImport.QUERY_ALL, query = "select dt from DataImport dt order by dt.createTime desc")
})
public class DataImport extends AuditVO {
	public enum State {
		DRAFT, IMPORTED, ERROR, REJECTED
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 9094603347250951107L;
	public final static String QUERY_BY_TABLE = "DataImport.QUERY_BY_TABLE";
	public final static String QUERY_ALL = "DataImport.QUERY_ALL";

	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE)
	@SequenceGenerator(allocationSize = 1, name = "SEQ_GEN_SEQUENCE")
	private Long id;
	private String fileUri;
	private String memo;
	private String dataDate;
	private String tableName;
	private String tableDesc;
	private String nodeCode;
	private String nodeName;
	@Column(name = "IS_OVERRIDE")
	private boolean overrideDuplication = true;
	@Column(name = "IS_INC_MODE")
	private boolean increasement = true;
	private String cleanDataClause;
	private Integer insertCount = 0;
	private Integer updateCount = 0;
	private Integer discardCount = 0;
	private String importMessage;
	@Enumerated(EnumType.STRING)
	private State importState = State.DRAFT;
	@OneToMany(cascade = CascadeType.ALL)
	@JoinColumn(name = "DATA_IMP_ID")
	@OrderBy("createTime")
	private List<DataImportAction> actions;
	/**
	 * @return the id
	 */
	@Override
	public Long getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the fileUri
	 */
	public String getFileUri() {
		return fileUri;
	}

	/**
	 * @param fileUri
	 *            the fileUri to set
	 */
	public void setFileUri(String fileUri) {
		this.fileUri = fileUri;
	}

	/**
	 * @return the memo
	 */
	public String getMemo() {
		return memo;
	}

	/**
	 * @param memo
	 *            the memo to set
	 */
	public void setMemo(String memo) {
		this.memo = memo;
	}

	/**
	 * @return the tableName
	 */
	public String getTableName() {
		return tableName;
	}

	/**
	 * @param tableName
	 *            the tableName to set
	 */
	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	/**
	 * 数据重复时，是否override? 增量数据后面的override前面的或是老数据，全量数据后面的override前面的数据
	 * 
	 * @return the overrideDuplication
	 */
	public boolean isOverrideDuplication() {
		return overrideDuplication;
	}

	/**
	 * @param overrideDuplication
	 *            the overrideDuplication to set
	 */
	public void setOverrideDuplication(boolean overrideDuplication) {
		this.overrideDuplication = overrideDuplication;
	}

	/**
	 * 是否增量数据，增量数据是添加到数据库，全量数据则先清除老数据，再导入新数据
	 * 
	 * @return the increasement
	 */
	public boolean isIncreasement() {
		return increasement;
	}

	/**
	 * @param inreasement
	 *            the increasement to set
	 */
	public void setIncreasement(boolean inreasement) {
		this.increasement = inreasement;
	}

	/**
	 * 本次导入添加到数据库的记录数
	 * 
	 * @return the insertCount
	 */
	public Integer getInsertCount() {
		return insertCount;
	}

	/**
	 * @param insertCount
	 *            the insertCount to set
	 */
	public void setInsertCount(Integer insertCount) {
		this.insertCount = insertCount;
	}

	/**
	 * 本次导入改写了多少条记录
	 * 
	 * @return the updateCount
	 */
	public Integer getUpdateCount() {
		return updateCount;
	}

	/**
	 * @param updateCount
	 *            the updateCount to set
	 */
	public void setUpdateCount(Integer updateCount) {
		this.updateCount = updateCount;
	}

	/**
	 * @return the discardCount
	 */
	public Integer getDiscardCount() {
		return discardCount;
	}

	/**
	 * 本次导入丢弃了多少条数据
	 * 
	 * @param discardCount
	 *            the discardCount to set
	 */
	public void setDiscardCount(Integer discardCount) {
		this.discardCount = discardCount;
	}

	/**
	 * @return the result
	 */
	public String getImportMessage() {
		return importMessage;
	}

	/**
	 * @param result
	 *            the result to set
	 */
	public void setImportMessage(String result) {
		this.importMessage = result;
	}

	/**
	 * @return the importResult
	 */
	public State getImportState() {
		return importState;
	}

	/**
	 * @param importResult
	 *            the importResult to set
	 */
	public void setImportState(State importResult) {
		this.importState = importResult;
	}

	public String getCleanDataClause() {
		return cleanDataClause;
	}

	public void setCleanDataClause(String cleanDataClause) {
		this.cleanDataClause = cleanDataClause;
	}

	public List<DataImportAction> getActions() {
		return actions;
	}

	public void setActions(List<DataImportAction> actions) {
		this.actions = actions;
	}

	public String getDataDate() {
		return dataDate;
	}

	public void setDataDate(String dataDate) {
		this.dataDate = dataDate;
	}

	public String getTableDesc() {
		return tableDesc;
	}

	public void setTableDesc(String tableDesc) {
		this.tableDesc = tableDesc;
	}

	public String getNodeCode() {
		return nodeCode;
	}

	public void setNodeCode(String nodeCode) {
		this.nodeCode = nodeCode;
	}

	public String getNodeName() {
		return nodeName;
	}

	public void setNodeName(String nodeName) {
		this.nodeName = nodeName;
	}

}
